﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data.Objects;
using System.Data;

namespace Southridge.Data
{

    public static class DBContext
    {
        private static SouthridgeDB _southridgeDB; 
        public static SouthridgeDB SouthridgeDB 
        { 
            get
            { 
                 lock ( typeof(DBContext)) 
                 { 
                     if ( _southridgeDB == null ) 
                        _southridgeDB = new SouthridgeDB(); 
                     return _southridgeDB ;
                 }   
            } 
        } 

    } 

    public partial class Address : global::System.Data.Objects.DataClasses.EntityObject, IDataErrorInfo
    {

        #region IDataErrorInfo Members

        public string Error
        {
            get { throw new NotImplementedException(); }
        }

        System.Text.RegularExpressions.Regex digitsOnly =
                new System.Text.RegularExpressions.Regex(@"^\d{5}(?:-\d{4})?$");
        public string this[string columnName]
        {
            get
            {                
                _errors.Remove(columnName); 

                switch (columnName)
                { 
                    case "ZipCode" : 
                    {
                        if (!digitsOnly.IsMatch(ZipCode))
                        {
                            _errors.Add(columnName, Resources.InvalidZipCode);
                            return (Resources.InvalidZipCode);
                        }                                                     
                    }
                        break; 
                    case "Address1": 
                        {
                            if (this.Address1 == string.Empty)
                            {
                                _errors.Add(columnName, Resources.AddressRequired);
                                return Resources.AddressRequired;
                            } 
                        } 
                        break; 
                    case "City": 
                        {
                            if (this.City == string.Empty)
                            {
                                _errors.Add(columnName, Resources.CityRequired);
                                return Resources.CityRequired;
                            } 
                        } 
                        break;

                    case "State":
                        {
                            if (this.State == string.Empty)
                            {
                                _errors.Add(columnName, Resources.StateRequired);
                                return Resources.StateRequired;
                            }
                        }
                        break; 
                } 
                
                
                return "";
            }
        }

        private Dictionary<string, string> _errors = new Dictionary<string, string>();  

         
        public bool IsValid
        {
            get
            {               
                return _errors.Count == 0 ;
            }
        }

        protected bool _isDirty = false; 
        public bool IsDirty
        {
            get
            {
                return _isDirty;
            }
            internal set
            {
                if (_isDirty != value)
                {
                    _isDirty = value;
                    OnPropertyChanged("IsDirty");
                }
            }

        }


        protected override void OnPropertyChanged(string property)
        {
            base.OnPropertyChanged(property);         
            IsDirty = true;
        }

        #endregion
    } 


     



    public partial class Preference 
    {
        public State _selectedState;
        public County _selectedCounty; 

        public State SelectedState
        {
            get { return _selectedState; } 
            set { _selectedState = value;
            OnPropertyChanged("SelectedState"); 
            }  
        }

        public County SelectedCounty
        {
            get { return _selectedCounty; }
            set
            {
                _selectedCounty = value;
                OnPropertyChanged("SelectedCounty");
            } 
        }    
    }

 
    public partial class Listing
    {
        private static int counter; 
        public List<string> Images
        {
            get
            {
                if ( Listing.counter++ % 2 == 1)
                {
                    return new List<string>()
                    {         
                            "pack://application:,,,/sampledata/3Main.png" , 
                            "pack://application:,,,/sampledata/3Bathroom.png", 
                            "pack://application:,,,/sampledata/3bedroom.png" , 
                            "pack://application:,,,/sampledata/3Dining.png" , 
                            "pack://application:,,,/sampledata/3Chimney.png" , 
                            "pack://application:,,,/sampledata/3Kitchen.png" , 
                            "pack://application:,,,/sampledata/3Living.png" 
                    }; 

                }
                else
                {
                    return new List<string>()
                    {                              
                            "pack://application:,,,/sampledata/1Main.png" , 
                            "pack://application:,,,/sampledata/1Bath.png", 
                            "pack://application:,,,/sampledata/1Closet.png" , 
                            "pack://application:,,,/sampledata/1Dining.png" , 
                            "pack://application:,,,/sampledata/1Fireplace.png" , 
                            "pack://application:,,,/sampledata/1Kitchen.png" , 
                            "pack://application:,,,/sampledata/1Living.png"   
                    }; 

                } 
            } 
        }


        public Neighborhood Neighborhood
        {
            get
            {
                Neighborhood n = new Neighborhood();
                n.IsHighGrowth = true;
                n.IsNearCenterCity = true;
                n.IsNearDining = true;
                n.IsNearParks = true;
                n.Name = "South Cove";
                return n;  
            } 
        } 
    } 
}
